#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File    : get_jsondata.py
# @Description : 读取json数据

import os
import json
from typing import List
from utils.logger import log
from conf.settings import DATA_DIR


def get_data(file: str, key: str):
    """
    json文件读取
    :param key:
    :param file: 文件路径
    :return:
    """
    file = os.path.join(DATA_DIR + "/json", file)
    try:
        with open(file, 'r', encoding='utf-8') as f:
            #print(f)
            data = json.load(f)
            #pop_comment(data[key])
            lst = pop_key(data[key])
            #print(lst)
        return lst
    except FileNotFoundError as e:
        log.error(e)
def pop_key(data: List = None):
    """
    把拿到的json数据转成符合pytest参数化的格式，即[('用例名称',请求参数),('用例名称',请求参数)]
    :param data:
    :return:
    """
    parametrize_data = []
    for v in data:
        parametrize_data.append(tuple(v.values()))
    return parametrize_data

# def pop_comment(data: List = None):
#     """删除场景说明_scene"""
#     for v in data:
#         if '_scene' in v:
#             v.pop('_scene')



if __name__ == '__main__':
    json_data = get_data('Maintenance_Workstation.json', key='hospital_management_insert')
    print(json_data)
    # for i in json_data:
    #     print(i[1])
    #     # for j in i:
    #     #     print(j)
    #     # print(i[0])
    #     # print(i[1])
